package pixiv

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

const AuthUrl = "https://oauth.secure.pixiv.net/auth/token"

const (
	clientID     = "MOBrBDS8blbauoSck0ZfDbtuzpyT"
	clientSecret = "lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj"
)

//type authParams struct {
//	GetSecureUrl int
//}

func Login() {
	client := &http.Client{}
	post := make(map[string]string)
	post["get_secure_url"] = "1"
	post["client_id"] = clientID
	post["client_secret"] = clientSecret
	post["grant_type"] = "password"
	post["username"] = "annghanyuu@gmail.com"
	post["password"] = "Freedomx102"
	bytesData, _ := json.Marshal(post)
	req, _ := http.NewRequest("POST", "https://oauth.secure.pixiv.net.cdn.cloudflare.net", bytes.NewReader(bytesData))
	//req, _ := http.NewRequest("POST", "https://oauth.secure.pixiv.net", bytes.NewReader(bytesData))
	req.Header.Set("User-Agent", "PixivAndroidApp/5.0.64 (Android 6.0)")
	resp, err := client.Do(req)
	if err != nil {
		fmt.Print(err.Error())
		return
	}

	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(body))
}
